<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : feedFO.xsl
    Created on : June 13, 2013, 12:07 AM
    Author     : Khanh
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:fu="http://xml.netbeans.org/schema/feed-user" exclude-result-prefixes="fu">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>

    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

            <fo:layout-master-set>

        <!-- layout information -->
                <fo:simple-page-master master-name="simple"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1cm"
                  margin-bottom="0cm"
                  margin-left="1.5cm"
                  margin-right="1.5cm">
                    <fo:region-body margin-top="2cm"/>
                    <fo:region-before extent="2cm"/>
                    <fo:region-after extent="2cm"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
        <!-- end: defines page layout -->

            <fo:page-sequence master-reference="simple">

      <!-- start fo:flow -->

                <fo:static-content flow-name="xsl-region-before">
                    <fo:block background-color="black" font-size="20pt" font-family="Tahoma"
        color="white" text-align="center">
                    Danh sách feed phổ biến nhất
                    </fo:block>
                </fo:static-content>



                <fo:flow flow-name="xsl-region-body">
                    <xsl:for-each select="//fu:feed">
                        <xsl:sort select="count(fu:userlist/fu:username)" order="descending"/>
                        <xsl:if test="not(position() > 5)">
                    <!-- 1 table la 1 user -->
                            <fo:table table-layout="fixed" width="100%" border-collapse="separate"
            font-family="Tahoma" border-width="0.5mm" border-style="solid"
            margin-bottom="7mm" padding-top="2mm" padding-bottom="2mm">
                                <fo:table-column column-width="10mm"/>
                                <fo:table-column column-width="60mm"/>
                                <fo:table-column column-width="100mm"/>
                                <fo:table-body>
                                    <fo:table-row>
                                        <fo:table-cell>
                                            <fo:block></fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell >
                                            <fo:block>Tên feed</fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell >
                                            <fo:block>
                                                <xsl:value-of select="fu:title"/>
                                            </fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>

                                    <fo:table-row>
                                        <fo:table-cell>
                                            <fo:block></fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell>
                                            <fo:block>Địa chỉ RSS</fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell >
                                            <fo:block>
                                                <xsl:value-of select="fu:url"/>
                                            </fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>
                                    
                                    <fo:table-row>
                                        <fo:table-cell>
                                            <fo:block></fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell >
                                            <fo:block>Miêu tả</fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell >
                                            <fo:block>
                                                <xsl:value-of select="fu:decription"/>
                                            </fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>

                                    <fo:table-row>
                                        <fo:table-cell>
                                            <fo:block></fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell>
                                            <fo:block>Số lượng người đọc feed này</fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell >
                                            <fo:block>
                                                <xsl:value-of select="count(fu:userlist/fu:username)"/>
                                            </fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>

                                    <fo:table-row>
                                        <fo:table-cell>
                                            <fo:block></fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell >
                                            <fo:block>Những người đọc feed này</fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell >
                                            <fo:block></fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>
                                    <xsl:for-each select="fu:userlist/fu:username">
                                        <fo:table-row>
                                            <fo:table-cell>
                                                <fo:block></fo:block>
                                            </fo:table-cell>
                                            <fo:table-cell >
                                                <fo:block></fo:block>
                                            </fo:table-cell>
                                            <fo:table-cell >
                                                <fo:block>
                                                    <xsl:value-of select="."/>
                                                </fo:block>
                                            </fo:table-cell>
                                        </fo:table-row>
                                    </xsl:for-each>
                                </fo:table-body>
                            </fo:table>
                        </xsl:if>
                    </xsl:for-each>
                </fo:flow> <!-- closes the flow element-->
            </fo:page-sequence> <!-- closes the page-sequence -->
        </fo:root>
    </xsl:template>

</xsl:stylesheet>
